<?php
// 添加自定义函数文件真他妈神奇

if (!function_exists('exampleFunction')) {
    /**
     * 创建自定义函数事例
     * @return string
     */
    function exampleFunction()
    {
        return 'this is an example';
    }
}

if (!function_exists('loginToken')) {
    /**
     * 生成登录TOKEN
     * @return string
     */
    function loginToken()
    {
        return md5(uniqid());
    }
}

if (!function_exists('permitsWithPath')) {
    /**
     * 返回拥有url的权限
     * @return string
     */
    function permitsWithPath($data)
    {
        $new = [];
        foreach ($data as $k => $v) {
            $v['path'] = getPermitPath($data, $v);
            $new[] = $v;
        }
        return $new;
    }
}

if (!function_exists('getPermitPath')) {
    /**
     * 创建自定义函数事例
     * @return string
     */
    function getPermitPath($all, $one)
    {
        if(0 == $one->pid){
            return $one->alias;
        }
        //找到父级的alias
        foreach($all as $v){
            if($v->id == $one->pid){
                return getPermitPath($all, $v)."/{$one->alias}";
            }
        }

    }
}
